package com.wuze.TCC.util;

import java.sql.Connection;
import java.util.Properties;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

/**
 * Druid工具类
 *
 * @author wuze
 */
public class DruidUtil{

    private static DruidDataSource druiddatasource = null;

    static {
        Properties properties = new Properties();
        try {
            properties.load(DruidUtil.class.getClassLoader().getResourceAsStream("dbconfig.properties"));
            druiddatasource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取数据库链接
     * @return 数据库链接
     */
    public static Connection getConnection() {
        try {
            return druiddatasource.getConnection();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("获取连接失败 请联系管理员【Connection】");
        }
    }



}


